package com.franklin.java.action.sql;

import com.franklin.java.action.sql.entity.GenerateEntityClassAction;
import com.franklin.java.action.sql.run.RunSqlAction;
import com.franklin.java.api.annotation.BaseAnnotation;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.psi.PsiElement;
import com.intellij.psi.xml.XmlTag;

/**
 * Sql Action组
 * @author Franklin
 * @since 2021/9/6 17:20
 */
public class SqlActionGroup extends DefaultActionGroup {

    private final PsiElement sqlActionElement;

    private MapColumnFixAction sqlAction;

    public SqlActionGroup(PsiElement sqlActionElement) {
        BaseAnnotation.initialize();
        this.sqlActionElement = sqlActionElement;
        MapColumnFixAction action = new MapColumnFixAction(sqlActionElement);
        sqlAction = action;
        this.add(action);
        this.add(new FindSqlUsagesAction(sqlActionElement));
        if (sqlActionElement instanceof XmlTag) {
            this.add(new GenerateEntityClassAction(sqlActionElement));
        }
        this.add(new RunSqlAction(sqlActionElement));
    }

    /**
     * 存储修改前的旧版本<br>
     * @author Franklin
     * @since 2021/9/8 12:06
     * @param :
     * @return void
     */
    public void storeOldSqlResult(){
        sqlAction.storeOldSqlResult();
    }
}
